home *** CD-ROM | disk | FTP | other *** search
/ Adobe Digital Video Collection / Digital Video Collection CD.iso / After Effects 5.5 / MMScriptEng.Cab / F115587_spring.mm < prev    next >
Encoding:
Text File  |  2001-12-07  |  1.3 KB  |  38 lines

  1. // One spring - version 1.2
  2.  
  3. // This script attaches a spring between the 2 layers shown in the popups.
  4. // Layer 1 keeps its original motion, while layer 2 is attached by a spring to it.
  5.  
  6. //      LAYER                                               PROPERTY                     CHANNEL
  7. //      ------                                              ----------                     --------
  8. // 1: Layer that moves                               doesn't matter               doesn't matter
  9. // 2: Layer attached to #1 by a spring        doesn't matter               doesn't matter
  10.  
  11.  
  12. if (time() == start_time) {
  13.    rest_length = 10;                            // rest length of spring in pixels
  14.    damp = 0.95;                                        // Damping (0 = infinite friction, 1 = none)
  15.  
  16.    p1 = value(pop_layer(1), position);
  17.    p2 = value(pop_layer(2), position);
  18.  
  19.    last_p1 = tmap(time() - step_time, value(pop_layer(1), position));
  20.    last_p2 = tmap(time() - step_time, value(pop_layer(2), position)); 
  21.  
  22.    v1 = (p1 - last_p1);
  23.    v2 = (p2 - last_p2);
  24. } else {
  25.   p1 = value(pop_layer(1), position);
  26.  
  27.    delta = p2 - p1;
  28.    n_delta = normalize(delta);
  29.  
  30.    a = 2 * n_delta * (length(delta) - rest_length) * step_time;
  31.  
  32.     v2 = (v2 - a) * damp;
  33.   v1 = (v1 + a) * damp;
  34.  
  35.    p1 = p1 + v1;
  36.    p2 = p2 + v2;
  37. }
  38. value(pop_layer(2), position) = p2;